<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initAutoloader()
	{
		 $loader = new Zend_Application_Module_Autoloader(
               array(
                  "namespace" => "",
                  "basePath" => APPLICATION_PATH."/modules/default")
               );

		 return $loader;
	}

	protected function _initSessions() {
		$this->bootstrap('session');
	}

	protected function _initActionHelpers()
	{
        Zend_Controller_Action_HelperBroker::addHelper(new Custom_Action_Helper_AssetsList());
    }


	protected function _initViewHelpers()
	{
		$this->bootstrap('layout');
		$layout = $this->getResource('layout');
		#Set view properties
		$view = $layout->getView();
		$view->setHelperPath('Custom/View/Helper', 'Custom_View_Helper');
		$view->doctype('XHTML1_STRICT');
		$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
		$view->headTitle()->setSeparator(' - ');
		$view->headTitle('Ciss');
	}

	protected function _initProjectSpecific()
    {
        $this->bootstrap("db");
        $db = $this->getResource("db");
		
		if($db->getProfiler()->getEnabled())
		{
			$db->setProfiler(new Zend_Db_Profiler_Firebug('All Db Queries'));
			$db->getProfiler()->setEnabled(true);
		}

        #read config ini file
		$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/config.ini','general');
		Zend_Registry::set('config', $config);

		#create session class and stored it in registry
		$customSession = new Zend_Session_Namespace('customSession');
		Zend_Registry::set('customSession', $customSession);

		#application logger
		$logger = new Zend_Log();
		$writer1 = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/data/logs/info');
		$logger->addWriter($writer1);

		$writer2 = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/data/logs/error');
		$logger->addWriter($writer2);

		// add a filter only to writer2
		$filter = new Zend_Log_Filter_Priority(Zend_Log::INFO);
		$writer1->addFilter($filter);

		$filter = new Zend_Log_Filter_Priority(Zend_Log::ERR);
		$writer2->addFilter($filter);

		Zend_Registry::set('logger',$logger);
		#end of logger
	}


	protected function _initRoutes()
	{
		$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/routes.ini');
		$router = Zend_Controller_Front::getInstance()->getRouter();
		$router->addConfig($config, 'routes');

	}

	protected function _initNavigation()
	{
		#set translation in navigation
		$locale  = (isset($vortex->language))?$vortex->language:'en';
		$navigation = null;
		if(file_exists(APPLICATION_PATH.'/configs/navigation/'.$locale.'.xml'))
		{
			$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation/'.$locale.'.xml','nav');
			$navigation = new Zend_Navigation($config);
		}
		
		// Set the navigation object to the view
        Zend_Layout::getMvcInstance()->getView()->navigation($navigation);
	}


	protected function _initPlugins()
	{
		// Access plugin
		$front = Zend_Controller_Front::getInstance();
		$front->registerPlugin(new Plugin_ModuleLayoutLoader());
	}

	protected function _initTranslations()
	{
		$translate = new Zend_Translate(
				array(
					'adapter' => 'array',
					'scan'=> Zend_Translate::LOCALE_FILENAME,
					'content' => APPLICATION_PATH.'/languages/en.php',
					'locale'  => 'en'
					));

		$translate->addTranslation(
			array(
				'content' => APPLICATION_PATH.'/languages/fr.php',
				'locale'  => 'fr'
				));


		$customSession = Zend_Registry::get('customSession');
		
		if(isset($customSession->language) && in_array($customSession->language, $translate->getList()))
		{
			$requestedLang = $customSession->language;
		}
		else
		{
			$requestedLang = 'en';
		}

		$translate->setLocale($requestedLang);

		Zend_Registry::set('translate', $translate);
	}
}

